class YCL_YBC_SWIFTSAP_DPC_EXT definition
  public
  inheriting from YCL_YBC_SWIFTSAP_DPC
  create public .

public section.

  methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM
    redefinition .
  methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION
    redefinition .
  methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY
    redefinition .
  methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET
    redefinition .
  methods /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM
    redefinition .
protected section.

  methods APPROVERSET_GET_ENTITYSET
    redefinition .
  methods ATTACHSET_DELETE_ENTITY
    redefinition .
  methods ATTACHSET_GET_ENTITY
    redefinition .
  methods ATTACHSET_GET_ENTITYSET
    redefinition .
  methods ATTACHSET_UPDATE_ENTITY
    redefinition .
  methods HISTORYSET_GET_ENTITYSET
    redefinition .
  methods REQJSONSET_GET_ENTITY
    redefinition .
  methods REQJSONSET_GET_ENTITYSET
    redefinition .
  methods REQUESTSET_GET_ENTITY
    redefinition .
  methods REQUESTSET_GET_ENTITYSET
    redefinition .
  methods USERSET_GET_ENTITY
    redefinition .
  methods USERSET_GET_ENTITYSET
    redefinition .
private section.
ENDCLASS.



CLASS YCL_YBC_SWIFTSAP_DPC_EXT IMPLEMENTATION.


  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
    DATA:
      LS_FILE         TYPE YBC_SWS_ATTACH,
      LS_KEY_TAB      TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR,
      LT_KEY_TAB      TYPE /IWBEP/T_MGW_NAME_VALUE_PAIR,
      LS_FILEMETADATA TYPE YBCS_SWS_ATTACH,
      LS_SWS_USER     TYPE YBC_SWS_USER.

    TRY .
        LS_FILE-ATTACHID = CL_SYSTEM_UUID=>CREATE_UUID_C32_STATIC( ).
      CATCH CX_UUID_ERROR INTO DATA(REF_CX).
    ENDTRY.

    SPLIT IV_SLUG AT ',' INTO LS_FILE-FILENAME LS_FILE-REQUESTID LS_FILE-USERID.
    CONDENSE:
      LS_FILE-FILENAME,
      LS_FILE-REQUESTID,
      LS_FILE-USERID.

    LS_FILE-ORIGIN = 'FROM APPROVER'. "来自于审批者上传
    LS_FILE-URL = '/sap/opu/odata/sap/YBC_SWIFTSAP_SRV/AttachSet(''' && LS_FILE-ATTACHID && ''')/$value'.
    LS_FILE-CONTENT    = IS_MEDIA_RESOURCE-VALUE.
    LS_FILE-MIMETYPE = IS_MEDIA_RESOURCE-MIME_TYPE.
    LS_FILE-FILESIZE = XSTRLEN( LS_FILE-CONTENT ).
    LS_FILE-UPLOADDATE  = SY-DATUM.
    LS_FILE-UPLOADTIME  = SY-UZEIT.
    SELECT SINGLE
      *
      INTO LS_SWS_USER
      FROM YBC_SWS_USER
     WHERE USERID = LS_FILE-USERID.
    CONCATENATE LS_SWS_USER-NAME1 LS_SWS_USER-NAME2 LS_SWS_USER-NAME3 INTO LS_FILE-USERNAME SEPARATED BY SPACE.
    CONDENSE LS_FILE-USERNAME.

    MODIFY YBC_SWS_ATTACH FROM LS_FILE.

    TRY.
        LS_KEY_TAB-NAME = 'ATTACHID'.
        LS_KEY_TAB-VALUE = LS_FILE-ATTACHID.
        APPEND LS_KEY_TAB TO LT_KEY_TAB.

        CALL METHOD ATTACHSET_GET_ENTITY
          EXPORTING
            IV_ENTITY_NAME     = IV_ENTITY_NAME
            IV_ENTITY_SET_NAME = IV_ENTITY_SET_NAME
            IV_SOURCE_NAME     = IV_SOURCE_NAME
            IT_KEY_TAB         = LT_KEY_TAB
            IT_NAVIGATION_PATH = IT_NAVIGATION_PATH
          IMPORTING
            ER_ENTITY          = LS_FILEMETADATA.

        COPY_DATA_TO_REF(
          EXPORTING
            IS_DATA = LS_FILEMETADATA
          CHANGING
            CR_DATA = ER_ENTITY ).

      CATCH /IWBEP/CX_MGW_BUSI_EXCEPTION.
      CATCH /IWBEP/CX_MGW_TECH_EXCEPTION.
    ENDTRY.
  ENDMETHOD.


  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.
    DATA:
      LS_PARAMETER     TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR,
      LS_MSG           TYPE BAPIRET2,
      LV_SENDBACKLEVEL TYPE YBC_SWS_APPLEVEL,
      LV_LANGUAGE      TYPE CHAR10,
      LS_APPROVER      TYPE YBC_SWS_APPROVER,
      LV_FORWARDAPPRS  TYPE CHAR200,
      LV_USERNAME      TYPE TEXT100,
      LV_PASSWORD      TYPE TEXT100,
      LV_NEWPWD        TYPE TEXT100,
      LV_BUDAT         TYPE BUDAT,
      LS_USER          TYPE YBCS_SWS_USER.

    CASE IV_ACTION_NAME.
      WHEN 'LoginOrChgpwd'.
        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Username'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_USERNAME = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Password'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_PASSWORD = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Newpwd'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_NEWPWD = LS_PARAMETER-VALUE.

        CALL FUNCTION 'YBC_SWS_LOGINORCHGPWD'
          EXPORTING
            IV_USERNAME = LV_USERNAME
            IV_PASSWORD = LV_PASSWORD
            IV_NEWPWD   = LV_NEWPWD
          IMPORTING
            ES_USER     = LS_USER.

        COPY_DATA_TO_REF(
          EXPORTING
            IS_DATA = LS_USER
          CHANGING
            CR_DATA = ER_DATA ).


      WHEN 'ProcessRequest'.
        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Requestid'.
        CONDENSE LS_PARAMETER-VALUE.
        LS_APPROVER-REQUESTID = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Approverid'.
        CONDENSE LS_PARAMETER-VALUE.
        LS_APPROVER-APPROVERID = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Applevel'.
        CONDENSE LS_PARAMETER-VALUE.
        LS_APPROVER-APPLEVEL = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Comments'.
        CONDENSE LS_PARAMETER-VALUE.
        LS_APPROVER-COMMENTS = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Action'.
        CONDENSE LS_PARAMETER-VALUE.
        LS_APPROVER-ACTION = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Sendbacklevel'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_SENDBACKLEVEL  = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Language'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_LANGUAGE  = LS_PARAMETER-VALUE.

        CLEAR LS_PARAMETER.
        READ TABLE IT_PARAMETER INTO LS_PARAMETER WITH KEY NAME = 'Forwardapprovers'.
        CONDENSE LS_PARAMETER-VALUE.
        LV_FORWARDAPPRS  = LS_PARAMETER-VALUE.

        CALL FUNCTION 'YBC_SWS_CALLBACK_REQUEST'
          EXPORTING
            IV_REQUESTID     = LS_APPROVER-REQUESTID
            IV_APPROVERID    = LS_APPROVER-APPROVERID
            IV_APPLEVEL      = LS_APPROVER-APPLEVEL
            IV_SENDBACKLEVEL = LV_SENDBACKLEVEL
            IV_ACTION        = LS_APPROVER-ACTION
            IV_COMMENTS      = LS_APPROVER-COMMENTS
            IV_FORWARDAPPRS  = LV_FORWARDAPPRS
            IV_LANGUAGE      = LV_LANGUAGE
          IMPORTING
            ES_MSG           = LS_MSG.

        COPY_DATA_TO_REF(
          EXPORTING
            IS_DATA = LS_MSG
          CHANGING
            CR_DATA = ER_DATA ).

      WHEN OTHERS.
        CALL METHOD SUPER->/IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.
    ENDCASE.

  ENDMETHOD.


  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITY.
    TYPES:
      TS_FROMUSER  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_USER,
      TT_TOREQUEST TYPE STANDARD TABLE OF YCL_YBC_SWIFTSAP_MPC=>TS_REQUEST WITH DEFAULT KEY.

    TYPES:
      BEGIN OF TY_DATA_USER.
        INCLUDE  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_USER.
    TYPES: CREATORREQUESTS TYPE TT_TOREQUEST. "必须和Navigation Properties 属性名称一致
    TYPES: APPROVERREQUESTS TYPE TT_TOREQUEST.
    TYPES: END OF TY_DATA_USER.

    TYPES:
      BEGIN OF TY_DATA_REQUEST.
        INCLUDE  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_REQUEST.
    TYPES: CREATOR TYPE TS_FROMUSER. "必须和Navigation Properties 属性名称一致
    TYPES: APPROVERS TYPE YCL_YBC_SWIFTSAP_MPC=>TS_USER.
    TYPES: END OF TY_DATA_REQUEST.

    DATA:
      LV_USERID       TYPE YBC_SWS_USER-USERID,
      LV_REQUESTID    TYPE YBC_SWS_REQUEST-REQUESTID,
      LS_DATA_USER    TYPE TY_DATA_USER,
      LS_DATA_REQUEST TYPE TY_DATA_REQUEST,
      LV_SET_NAME     TYPE /IWBEP/MGW_TECH_NAME,
      LS_MESSAGE      TYPE SCX_T100KEY.

    LV_SET_NAME = IO_TECH_REQUEST_CONTEXT->GET_ENTITY_SET_NAME( ).
    CASE LV_SET_NAME.
      WHEN 'UserSet'.
        READ TABLE IT_KEY_TAB INTO DATA(LS_KEY_TAB) WITH KEY NAME = 'Userid'.
        IF SY-SUBRC = 0.

          LV_USERID = LS_KEY_TAB-VALUE.
          SELECT SINGLE
            *
            FROM YBC_SWS_USER
            INTO CORRESPONDING FIELDS OF LS_DATA_USER
           WHERE USERID = LV_USERID.
          IF SY-SUBRC <> 0.
*            LS_MESSAGE-MSGID = 'YBC_SWS'.
*            LS_MESSAGE-MSGNO = '002'.
*
*            RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
*              EXPORTING
*                TEXTID = LS_MESSAGE.

            RETURN.
          ENDIF.

          SELECT *
            FROM YBC_SWS_REQUEST
            INTO CORRESPONDING FIELDS OF TABLE LS_DATA_USER-CREATORREQUESTS
           WHERE USERID = LV_USERID.

          COPY_DATA_TO_REF(
            EXPORTING IS_DATA = LS_DATA_USER
             CHANGING CR_DATA = ER_ENTITY
          ).

        ENDIF.

      WHEN 'RequestSet'.
        READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'Requestid'.
        IF SY-SUBRC = 0.
          LV_REQUESTID = LS_KEY_TAB-VALUE.
          SELECT SINGLE
            *
            FROM YBC_SWS_REQUEST
            INTO CORRESPONDING FIELDS OF LS_DATA_REQUEST
           WHERE REQUESTID = LV_REQUESTID.
          IF SY-SUBRC <> 0.
*            LS_MESSAGE-MSGID = 'YBC_SWS'.
*            LS_MESSAGE-MSGNO = '002'.
*
*            RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
*              EXPORTING
*                TEXTID = LS_MESSAGE.
            RETURN.
          ENDIF.

          SELECT SINGLE *
            FROM YBC_SWS_USER
            INTO CORRESPONDING FIELDS OF LS_DATA_REQUEST-CREATOR
           WHERE USERID = LS_DATA_REQUEST-USERID.

          COPY_DATA_TO_REF(
            EXPORTING IS_DATA = LS_DATA_REQUEST
             CHANGING CR_DATA = ER_ENTITY
          ).

        ENDIF.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.


  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET.

    TYPES:
      TS_FROMUSER  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_USER.

    TYPES:
      BEGIN OF TY_DATA_REQUEST.
        INCLUDE  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_REQUEST.
    TYPES: CREATOR TYPE TS_FROMUSER. "必须和Navigation Properties 属性名称一致
    TYPES: APPROVERS TYPE YCL_YBC_SWIFTSAP_MPC=>TS_USER.
    TYPES: END OF TY_DATA_REQUEST.

    DATA:
      LV_USERID       TYPE YBC_SWS_USER-USERID,
      LV_REQUESTID    TYPE YBC_SWS_REQUEST-REQUESTID,
      LT_REQUEST      TYPE YCL_YBC_SWIFTSAP_MPC=>TT_REQUEST,
      LS_DATA_REQUEST TYPE TY_DATA_REQUEST,
      LT_DATA_REQUEST TYPE STANDARD TABLE OF TY_DATA_REQUEST,
      LV_SET_NAME     TYPE /IWBEP/MGW_TECH_NAME,
      LS_MESSAGE      TYPE SCX_T100KEY,
      LS_FILTER       TYPE /IWBEP/S_MGW_SELECT_OPTION,
      LV_LANGUAGE     TYPE CHAR10.

    LV_SET_NAME = IO_TECH_REQUEST_CONTEXT->GET_ENTITY_SET_NAME( ).
    CASE LV_SET_NAME.
      WHEN 'RequestSet'.

        REQUESTSET_GET_ENTITYSET(
          EXPORTING
            IV_ENTITY_NAME = IV_ENTITY_NAME
            IV_ENTITY_SET_NAME = IV_ENTITY_SET_NAME
            IV_SOURCE_NAME = IV_SOURCE_NAME
            IT_FILTER_SELECT_OPTIONS = IT_FILTER_SELECT_OPTIONS
            IS_PAGING = IS_PAGING
            IT_KEY_TAB = IT_KEY_TAB
            IT_NAVIGATION_PATH = IT_NAVIGATION_PATH
            IT_ORDER = IT_ORDER
            IV_FILTER_STRING = IV_FILTER_STRING
            IV_SEARCH_STRING = IV_SEARCH_STRING
            IO_TECH_REQUEST_CONTEXT = IO_TECH_REQUEST_CONTEXT
         IMPORTING
            ET_ENTITYSET = LT_REQUEST
        ).

*        IF LT_REQUEST IS INITIAL.
*          LS_MESSAGE-MSGID = 'YBC_SWS'.
*          LS_MESSAGE-MSGNO = '002'.
*
*          RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
*            EXPORTING
*              TEXTID = LS_MESSAGE.
*        ENDIF.

        "多语言
        CLEAR LS_FILTER.
        READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
          WITH KEY PROPERTY = 'Message'.
        LOOP AT LS_FILTER-SELECT_OPTIONS INTO DATA(LS_LANGUAGE).
          LV_LANGUAGE = LS_LANGUAGE-LOW.
          EXIT.
        ENDLOOP.
        IF LV_LANGUAGE IS INITIAL.
          LV_LANGUAGE = 'zh'. "默认中文
        ENDIF.
        TRANSLATE LV_LANGUAGE TO LOWER CASE.

        LOOP AT LT_REQUEST INTO DATA(LS_REQUEST).
          MOVE-CORRESPONDING LS_REQUEST TO LS_DATA_REQUEST.

          SELECT SINGLE *
                  FROM YBC_SWS_USER
                  INTO CORRESPONDING FIELDS OF LS_DATA_REQUEST-CREATOR
                 WHERE USERID = LS_DATA_REQUEST-USERID.
          IF LV_LANGUAGE CS 'zh'.
            LS_DATA_REQUEST-CREATOR-NAME3 = LS_DATA_REQUEST-CREATOR-NAME1.
          ELSEIF LV_LANGUAGE CS 'en'.
            LS_DATA_REQUEST-CREATOR-NAME3 = LS_DATA_REQUEST-CREATOR-NAME2.
          ENDIF.

          APPEND LS_DATA_REQUEST TO LT_DATA_REQUEST.
        ENDLOOP.

        COPY_DATA_TO_REF(
          EXPORTING IS_DATA = LT_DATA_REQUEST
           CHANGING CR_DATA = ER_ENTITYSET
        ).

      WHEN OTHERS.
    ENDCASE.


  ENDMETHOD.


  METHOD /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM.
    DATA:
      LV_STR      TYPE STRING,
      LV_ATTACHID TYPE YBC_SWS_ATTACH-ATTACHID,
      LS_ATTACH   TYPE YBC_SWS_ATTACH,
      LT_KEYS     TYPE /IWBEP/T_MGW_TECH_PAIRS,
      LS_KEY      TYPE /IWBEP/S_MGW_TECH_PAIR,
      LS_STREAM   TYPE TY_S_MEDIA_RESOURCE.

    LT_KEYS = IO_TECH_REQUEST_CONTEXT->GET_KEYS( ).
    READ TABLE LT_KEYS WITH KEY NAME = 'ATTACHID' INTO LS_KEY.

    LV_ATTACHID = LS_KEY-VALUE.
    SELECT SINGLE *
         FROM YBC_SWS_ATTACH
         INTO LS_ATTACH
         WHERE ATTACHID = LV_ATTACHID.
    IF SY-SUBRC <> 0.
      RETURN.
    ENDIF.

    DATA:
      LS_RESPONSE_HEADER TYPE IHTTPNVP,
      LV_FILENAME        TYPE STRING.

    LS_STREAM-MIME_TYPE = LS_ATTACH-MIMETYPE.
    LS_STREAM-VALUE = LS_ATTACH-CONTENT.
    LV_STR = LS_ATTACH-FILENAME.
    LV_STR = CL_HTTP_UTILITY=>ESCAPE_URL( LV_STR ).


    LS_RESPONSE_HEADER-NAME = 'content-disposition'.
    "CONCATENATE 'attachment; filename=' LV_STR INTO LS_RESPONSE_HEADER-VALUE ."直接下载
    CONCATENATE 'inline; filename=' LV_STR INTO LS_RESPONSE_HEADER-VALUE . "先预览再下载

    SET_HEADER( LS_RESPONSE_HEADER ).

    COPY_DATA_TO_REF( EXPORTING IS_DATA = LS_STREAM
                      CHANGING  CR_DATA = ER_STREAM ).
  ENDMETHOD.


  METHOD APPROVERSET_GET_ENTITYSET.

    DATA:
      LV_TOP      TYPE I,
      LV_SKIP     TYPE I,
      LS_MSG      TYPE BAPIRET2,
      LS_MESSAGE  TYPE SCX_T100KEY,
      LS_FILTER   TYPE /IWBEP/S_MGW_SELECT_OPTION,
      LV_WFCONFID TYPE YBC_SWS_WFCONFID,
      LV_APPLEVEL TYPE YBC_SWS_APPLEVEL,
      LV_USERID   TYPE YBC_SWS_USER-USERID,
      LS_APPROVER TYPE YBCS_SWS_APPROVER,
      LT_APPROVER TYPE STANDARD TABLE OF YBCS_SWS_APPROVER,
      LS_ENTITY   LIKE LINE OF ET_ENTITYSET.

    "查找转发人，ApplevelDesc1 存应用ID
    CLEAR LS_FILTER.
    READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
      WITH KEY PROPERTY = 'ApplevelDesc1'.
    LOOP AT LS_FILTER-SELECT_OPTIONS INTO DATA(LS_OPT).
      CONDENSE LS_OPT-LOW.

      SELECT SINGLE WFCONFID
        INTO LV_WFCONFID
        FROM YBC_SWS_APP_CNFG
       WHERE APPID = LS_OPT-LOW.
      EXIT.
    ENDLOOP.

    CLEAR LS_FILTER.
    READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
      WITH KEY PROPERTY = 'Applevel'.
    LOOP AT LS_FILTER-SELECT_OPTIONS INTO LS_OPT.
      CONDENSE LS_OPT-LOW.
      LV_APPLEVEL = LS_OPT-LOW.
      EXIT.
    ENDLOOP.

    IF LV_WFCONFID IS INITIAL OR LV_APPLEVEL IS INITIAL.
      RETURN.
    ENDIF.

    CALL FUNCTION 'YBC_SWS_GET_APPROVER'
      EXPORTING
        IV_WFCONFID    = LV_WFCONFID
        IV_APPLEVEL    = LV_APPLEVEL
        IV_FIRST_LEVEL = 'X'
      IMPORTING
        ES_MSG         = LS_MSG
      TABLES
*       IT_REQ_HEADER  =
        ET_APPROVER    = LT_APPROVER.

    IF LS_MSG-TYPE = 'E'.
      RETURN.
    ENDIF.

    "过滤掉自己
    CLEAR LS_FILTER.
    READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
      WITH KEY PROPERTY = 'Userid'.
    LOOP AT LS_FILTER-SELECT_OPTIONS INTO LS_OPT.
      CONDENSE LS_OPT-LOW.
      LV_USERID = LS_OPT-LOW.
      EXIT.
    ENDLOOP.
    IF LV_USERID IS NOT INITIAL.
      DELETE LT_APPROVER WHERE USERID = LV_USERID.
    ENDIF.


    LOOP AT LT_APPROVER INTO LS_APPROVER.
      CLEAR LS_ENTITY.
      MOVE-CORRESPONDING LS_APPROVER TO LS_ENTITY.
      APPEND LS_ENTITY TO ET_ENTITYSET.
    ENDLOOP.

    "top 和 skip实现
    DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

    LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
    LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
    IF LV_SKIP IS NOT INITIAL OR
      LV_TOP IS NOT INITIAL.

      DO LV_SKIP TIMES.
        DELETE ET_ENTITYSET INDEX 1.
      ENDDO.

      LOOP AT ET_ENTITYSET INTO DATA(LS_ENTITYSET).
        IF SY-TABIX > LV_TOP.
          DELETE ET_ENTITYSET.
        ENDIF.

      ENDLOOP.
    ENDIF.

    IF IT_ORDER[] IS NOT INITIAL.
      DATA:
        LT_SORT TYPE ABAP_SORTORDER_TAB,
        LS_SORT TYPE ABAP_SORTORDER.

      LOOP AT IT_ORDER INTO DATA(LS_ORDER).
        CLEAR LS_SORT.
        LS_SORT-NAME = LS_ORDER-PROPERTY.
        IF LS_ORDER-ORDER = 'desc'.
          LS_SORT-DESCENDING = 'X'.
        ENDIF.
        APPEND LS_SORT TO LT_SORT.
      ENDLOOP.
      SORT ET_ENTITYSET BY (LT_SORT).
    ENDIF.
  ENDMETHOD.


  METHOD ATTACHSET_DELETE_ENTITY.

    DATA:
      LV_ATTACHID TYPE YBC_SWS_ATTACH-ATTACHID,
      LS_KEY_TAB  TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.

    DATA:
      LS_MESSAGE TYPE SCX_T100KEY,
      LS_HEADER  TYPE IHTTPNVP.

    CLEAR LS_KEY_TAB.
    READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'ATTACHID'.
    LV_ATTACHID = LS_KEY_TAB-VALUE.
    IF LV_ATTACHID IS NOT INITIAL.
      DELETE FROM YBC_SWS_ATTACH WHERE ATTACHID = LV_ATTACHID.
      IF SY-SUBRC = 0.
        COMMIT WORK.

        LS_HEADER-NAME  = 'ZRETMSG'.
        LS_HEADER-VALUE = '{Type:S, Desc:Record deleted successfully}'.
        /IWBEP/IF_MGW_CONV_SRV_RUNTIME~SET_HEADER( LS_HEADER ).
      ELSE.
        ROLLBACK WORK.

        LS_HEADER-NAME  = 'ZRETMSG'.
        LS_HEADER-VALUE = '{Type:E, Desc:Record deleted failed}'.
        /IWBEP/IF_MGW_CONV_SRV_RUNTIME~SET_HEADER( LS_HEADER ).
      ENDIF.
    ENDIF.
  ENDMETHOD.


  METHOD ATTACHSET_GET_ENTITY.
    DATA:
      LV_ATTACHID TYPE YBC_SWS_ATTACH-ATTACHID,
      LS_KEY_TAB  TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.
    DATA:
      LS_MESSAGE TYPE SCX_T100KEY.

    "Fiori 不会调用

    CLEAR LS_KEY_TAB.
    READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'ATTACHID'.
    LV_ATTACHID = LS_KEY_TAB-VALUE.

    SELECT SINGLE *
      FROM YBC_SWS_ATTACH
      INTO CORRESPONDING FIELDS OF ER_ENTITY
      WHERE ATTACHID = LV_ATTACHID.
    IF SY-SUBRC <> 0.
      RETURN.
    ENDIF.
  ENDMETHOD.


  METHOD ATTACHSET_GET_ENTITYSET.
    DATA:
      LV_TOP     TYPE I,
      LV_SKIP    TYPE I,
      LS_MESSAGE TYPE SCX_T100KEY,
      LS_ENTITY  LIKE LINE OF ET_ENTITYSET,
      LS_ATTACH  TYPE YBC_SWS_ATTACH,
      LT_ATTACH  TYPE STANDARD TABLE OF YBC_SWS_ATTACH.

    SELECT
      ATTACHID
      REQUESTID
      ORIGIN
      FILENAME
      FILETYPE
      FILESIZE
      MIMETYPE
      UPLOADDATE
      UPLOADTIME
      USERID
      USERNAME
      URL
      FROM YBC_SWS_ATTACH
      INTO CORRESPONDING FIELDS OF TABLE LT_ATTACH
      WHERE (IV_FILTER_STRING).
    IF SY-SUBRC <> 0.
      RETURN.
    ELSE.

      SORT LT_ATTACH BY UPLOADDATE DESCENDING UPLOADTIME DESCENDING.

      LOOP AT LT_ATTACH INTO LS_ATTACH.
        CLEAR LS_ENTITY.
        MOVE-CORRESPONDING LS_ATTACH TO LS_ENTITY.
        LS_ENTITY-UPLOADDT = LS_ATTACH-UPLOADDATE && LS_ATTACH-UPLOADTIME.
        APPEND LS_ENTITY TO ET_ENTITYSET.
      ENDLOOP.

      "top 和 skip实现
      DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

      LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
      LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
      IF LV_SKIP IS NOT INITIAL OR
        LV_TOP IS NOT INITIAL.

        DO LV_SKIP TIMES.
          DELETE ET_ENTITYSET INDEX 1.
        ENDDO.

        LOOP AT ET_ENTITYSET INTO DATA(LS_ENTITYSET).
          IF SY-TABIX > LV_TOP.
            DELETE ET_ENTITYSET.
          ENDIF.

        ENDLOOP.
      ENDIF.
    ENDIF.

    IF IT_ORDER[] IS NOT INITIAL.
      DATA:
        LT_SORT TYPE ABAP_SORTORDER_TAB,
        LS_SORT TYPE ABAP_SORTORDER.

      LOOP AT IT_ORDER INTO DATA(LS_ORDER).
        CLEAR LS_SORT.
        LS_SORT-NAME = LS_ORDER-PROPERTY.
        IF LS_ORDER-ORDER = 'desc'.
          LS_SORT-DESCENDING = 'X'.
        ENDIF.
        APPEND LS_SORT TO LT_SORT.
      ENDLOOP.
      SORT ET_ENTITYSET BY (LT_SORT).
    ENDIF.
  ENDMETHOD.


  METHOD ATTACHSET_UPDATE_ENTITY.
    DATA:
      LS_ATTACH  TYPE YCL_YBC_SWIFTSAP_MPC=>TS_ATTACH,
      LS_KEY_TAB TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR,
      LS_HEADER  TYPE IHTTPNVP.

    IO_DATA_PROVIDER->READ_ENTRY_DATA( IMPORTING ES_DATA = LS_ATTACH ).
    IF LS_ATTACH-ATTACHID IS INITIAL.
      CLEAR LS_KEY_TAB.
      READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'ATTACHID'.
      LS_ATTACH-ATTACHID = LS_KEY_TAB-VALUE.
    ENDIF.

    UPDATE YBC_SWS_ATTACH SET FILENAME = LS_ATTACH-FILENAME
                        WHERE ATTACHID = LS_ATTACH-ATTACHID.
    IF SY-SUBRC = 0.
      COMMIT WORK.
      ER_ENTITY = LS_ATTACH.

      LS_HEADER-NAME  = 'ZRETMSG'.
      LS_HEADER-VALUE = '{Type:S, Desc:Record updated successfully}'.
      /IWBEP/IF_MGW_CONV_SRV_RUNTIME~SET_HEADER( LS_HEADER ).
    ELSE.
      ROLLBACK WORK.
      LS_HEADER-NAME  = 'ZRETMSG'.
      LS_HEADER-VALUE = '{Type:E, Desc:Record updated failed}'.
      /IWBEP/IF_MGW_CONV_SRV_RUNTIME~SET_HEADER( LS_HEADER ).
    ENDIF.
  ENDMETHOD.


  METHOD HISTORYSET_GET_ENTITYSET.
    DATA:
      LV_TOP  TYPE I,
      LV_SKIP TYPE I.

    DATA:
      LV_SQL_STR   TYPE STRING,
      LV_INDEX     TYPE NUM2,
      LV_FIELD     TYPE STRING,
      LS_FILTER    TYPE /IWBEP/S_MGW_SELECT_OPTION,
      LT_RANGE01   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE02   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE03   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE04   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE05   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE06   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE07   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE08   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE09   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE10   TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LS_APPROVER  TYPE YBC_SWS_APPROVER,
      LT_APPROVER  TYPE STANDARD TABLE OF YBC_SWS_APPROVER,
      LS_ENTITYSET LIKE LINE OF ET_ENTITYSET,
      LS_USER      TYPE YBC_SWS_USER,
      LT_USER      TYPE STANDARD TABLE OF YBC_SWS_USER,
      LS_MESSAGE   TYPE SCX_T100KEY.

    FIELD-SYMBOLS <FS_FIELD> TYPE ANY TABLE.

    LV_INDEX = 0.
    LOOP AT IT_FILTER_SELECT_OPTIONS INTO LS_FILTER WHERE PROPERTY <> 'Approver_name'.
      LV_INDEX = LV_INDEX + 1.
      LV_FIELD = 'LT_RANGE' && LV_INDEX.
      ASSIGN (LV_FIELD) TO <FS_FIELD>.
      <FS_FIELD> = LS_FILTER-SELECT_OPTIONS.

      IF LV_INDEX <= 1.
        CONCATENATE LS_FILTER-PROPERTY 'IN' LV_FIELD INTO
          LV_SQL_STR  SEPARATED BY SPACE.
      ELSE.
        CONCATENATE LV_SQL_STR 'AND' LS_FILTER-PROPERTY 'IN' LV_FIELD INTO
           LV_SQL_STR  SEPARATED BY SPACE.
      ENDIF.

      IF LV_INDEX >= 10.
        EXIT.
      ENDIF.
    ENDLOOP.

    SELECT *
      FROM YBC_SWS_APPROVER
      INTO TABLE LT_APPROVER
      WHERE (LV_SQL_STR).

    IF SY-SUBRC <> 0.
      RETURN.
    ELSE.

      "只显示实际处理者
      SELECT
        YBC_SWS_REQUEST~REQUESTID,
        YBC_SWS_APP_CNFG~APPID,
        YBC_SWS_APP_CNFG~FLG_ACTLPROC_ONLY
        INTO TABLE @DATA(LT_APP_CNFG)
        FROM YBC_SWS_APP_CNFG
        JOIN YBC_SWS_REQUEST
          ON YBC_SWS_APP_CNFG~APPID = YBC_SWS_REQUEST~APPID
         FOR ALL ENTRIES IN @LT_APPROVER
       WHERE YBC_SWS_REQUEST~REQUESTID = @LT_APPROVER-REQUESTID.

      SELECT
        ACTION,
        SEQNR,
        DESC1,
        DESC2,
        DESC3
      INTO TABLE @DATA(LT_APP_ACTION)
      FROM YBC_SWS_APP_ACT
      JOIN YBC_SWS_REQUEST
        ON YBC_SWS_APP_ACT~APPID = YBC_SWS_REQUEST~APPID
       FOR ALL ENTRIES IN @LT_APPROVER
     WHERE YBC_SWS_REQUEST~REQUESTID = @LT_APPROVER-REQUESTID.

      SORT LT_APP_ACTION BY ACTION.

      LOOP AT LT_APPROVER INTO LS_APPROVER.
        LV_INDEX = SY-TABIX.
        IF LS_APPROVER-PROCESSED IS NOT INITIAL AND LS_APPROVER-ACTUALPROCESSED IS INITIAL.
          READ TABLE LT_APP_CNFG INTO DATA(LS_APP_CNFG) WITH KEY REQUESTID = LS_APPROVER-REQUESTID.
          IF LS_APP_CNFG-FLG_ACTLPROC_ONLY IS NOT INITIAL.
            DELETE LT_APPROVER INDEX LV_INDEX.
          ENDIF.
        ENDIF.
      ENDLOOP.

      SELECT *
        INTO TABLE LT_USER
        FROM YBC_SWS_USER
        FOR ALL ENTRIES IN LT_APPROVER
       WHERE USERID = LT_APPROVER-APPROVERID.

      SORT LT_USER BY USERID ASCENDING.

      LOOP AT LT_APPROVER INTO LS_APPROVER.
        CLEAR LS_ENTITYSET.
        MOVE-CORRESPONDING LS_APPROVER TO LS_ENTITYSET.
        CONCATENATE LS_APPROVER-RDATE LS_APPROVER-RTIME INTO LS_ENTITYSET-RDATETIME.
        CONCATENATE LS_APPROVER-ADATE LS_APPROVER-ATIME INTO LS_ENTITYSET-ADATETIME.
        CONCATENATE LS_APPROVER-COMMENTS LS_APPROVER-REMARKS INTO LS_ENTITYSET-COMMENTS SEPARATED BY SPACE.

        CLEAR LS_USER.
        READ TABLE LT_USER INTO LS_USER WITH KEY USERID = LS_APPROVER-APPROVERID.
        IF SY-SUBRC = 0.
          CONCATENATE LS_USER-NAME1 LS_USER-NAME2 LS_USER-NAME3 INTO
          LS_ENTITYSET-APPROVER_NAME SEPARATED BY SPACE.
        ENDIF.

        IF LS_APPROVER-ACTION IS NOT INITIAL.
          READ TABLE LT_APP_ACTION INTO DATA(LS_APP_ACTION)
            WITH KEY ACTION = LS_APPROVER-ACTION  BINARY SEARCH.
          IF SY-SUBRC = 0.
            LS_ENTITYSET-ACTION_DESC1 = LS_APP_ACTION-DESC1.
            LS_ENTITYSET-ACTION_DESC2 = LS_APP_ACTION-DESC2.
            LS_ENTITYSET-ACTION_DESC3 = LS_APP_ACTION-DESC3.
          ENDIF.

        ENDIF.

        CONDENSE LS_ENTITYSET-APPROVER_NAME.
        CONDENSE LS_ENTITYSET-COMMENTS.

        IF LS_ENTITYSET-ACTUALPROCESSED IS NOT INITIAL.
          IF ( LS_ENTITYSET-COMMENTS = 'Creator Same as LM Approver, Auto Skip'
            OR LS_ENTITYSET-COMMENTS = 'LM Approver Same as FUM Approver, Auto Skip' ).
            LS_ENTITYSET-ACTUALPROCESSED = 'Skipped'.
          ELSE.
            LS_ENTITYSET-ACTUALPROCESSED = 'Completed'.
          ENDIF.

        ENDIF.

        APPEND LS_ENTITYSET TO ET_ENTITYSET.
      ENDLOOP.

      SORT ET_ENTITYSET BY REQUESTID ASCENDING RDATETIME ASCENDING ADATETIME ASCENDING.

      "top 和 skip实现
      DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

      LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
      LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
      IF LV_SKIP IS NOT INITIAL OR
        LV_TOP IS NOT INITIAL.

        DO LV_SKIP TIMES.
          DELETE ET_ENTITYSET INDEX 1.
        ENDDO.

        LOOP AT ET_ENTITYSET INTO LS_ENTITYSET.
          IF SY-TABIX > LV_TOP.
            DELETE ET_ENTITYSET.
          ENDIF.

        ENDLOOP.
      ENDIF.

      IF IT_ORDER[] IS NOT INITIAL.
        DATA:
          LT_SORT TYPE ABAP_SORTORDER_TAB,
          LS_SORT TYPE ABAP_SORTORDER.

        LOOP AT IT_ORDER INTO DATA(LS_ORDER).
          CLEAR LS_SORT.
          LS_SORT-NAME = LS_ORDER-PROPERTY.
          IF LS_ORDER-ORDER = 'desc'.
            LS_SORT-DESCENDING = 'X'.
          ENDIF.
          APPEND LS_SORT TO LT_SORT.
        ENDLOOP.
        SORT ET_ENTITYSET BY (LT_SORT).
      ENDIF.
    ENDIF.
  ENDMETHOD.


  METHOD REQJSONSET_GET_ENTITY.
    DATA:
      LV_CATEGORY3 TYPE YBC_SWS_CATOT, "Category(Other Language)
      LV_REQUESTID TYPE YBC_SWS_REQUEST-REQUESTID,
      LS_KEY_TAB   TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.

    DATA:
      LS_MESSAGE    TYPE SCX_T100KEY,
      LS_ATTACH     TYPE YBC_SWS_ATTACH,
      LS_ATTACHJSON TYPE YBCS_SWS_ATTACH,
      LT_ATTACH     TYPE STANDARD TABLE OF YBC_SWS_ATTACH,
      LT_ATTACHJSON TYPE STANDARD TABLE OF YBCS_SWS_ATTACH.

    CLEAR LS_KEY_TAB.
    READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'Requestid'.
    LV_REQUESTID = LS_KEY_TAB-VALUE.

    SELECT SINGLE *
      FROM YBC_SWS_REQJSON
      INTO CORRESPONDING FIELDS OF ER_ENTITY
      WHERE REQUESTID = LV_REQUESTID.
    IF SY-SUBRC <> 0.
      RETURN.
    ENDIF.

* 增加过账日期

    SELECT SINGLE
      CATEGORY3
      INTO LV_CATEGORY3
      FROM YBC_SWS_REQUEST
      WHERE REQUESTID = LV_REQUESTID.

    ER_ENTITY-HEADJSON = ER_ENTITY-HEADJSON+1.
    IF     LV_CATEGORY3 IS NOT INITIAL.
      CONCATENATE LV_CATEGORY3(4) LV_CATEGORY3+4(2) LV_CATEGORY3+6(2)
           INTO LV_CATEGORY3 SEPARATED BY '.'.
      IF LV_CATEGORY3 = '0000.00.00'.
        CLEAR LV_CATEGORY3.
      ENDIF.
    ENDIF.

    CONCATENATE '[{"FIELD":"FI_BUDAT","NAME1":"","NAME2":"","NAME3":"","VALUE":"' LV_CATEGORY3 '","PLATFORM":""},'
      ER_ENTITY-HEADJSON INTO ER_ENTITY-HEADJSON.


    "获取附件信息
    SELECT
      *
      INTO TABLE LT_ATTACH
      FROM YBC_SWS_ATTACH
     WHERE REQUESTID = LV_REQUESTID.
    IF SY-SUBRC = 0.
      SORT LT_ATTACH BY UPLOADDATE DESCENDING UPLOADTIME DESCENDING.

      LOOP AT LT_ATTACH INTO LS_ATTACH.
        CLEAR LS_ATTACHJSON.
        CLEAR LS_ATTACH-CONTENT.

        MOVE-CORRESPONDING LS_ATTACH TO LS_ATTACHJSON.
        LS_ATTACHJSON-UPLOADDT = LS_ATTACH-UPLOADDATE && LS_ATTACH-UPLOADTIME.
        APPEND LS_ATTACHJSON TO LT_ATTACHJSON.
      ENDLOOP.

      ER_ENTITY-ATTACHJSON =  /UI2/CL_JSON=>SERIALIZE( DATA = LT_ATTACHJSON ).
    ENDIF.
  ENDMETHOD.


  METHOD REQJSONSET_GET_ENTITYSET.
    DATA:
      LV_TOP  TYPE I,
      LV_SKIP TYPE I.

    DATA:
      LV_SQL_STR TYPE STRING,
      LV_USERID  TYPE YBC_SWS_REQUEST-USERID,
      LS_MESSAGE TYPE SCX_T100KEY.

    "Fiori 不会调用

    IF IT_KEY_TAB[] IS NOT INITIAL.
      READ TABLE IT_KEY_TAB INTO DATA(LS_KEY_TAB)
        WITH KEY NAME = 'Userid'.
      LV_USERID = LS_KEY_TAB-VALUE.

      IF LV_USERID IS NOT INITIAL.
        IF IV_FILTER_STRING IS INITIAL.
          CONCATENATE 'USERID = ''' LV_USERID '''' INTO LV_SQL_STR.
        ELSE.
          CONCATENATE IV_FILTER_STRING 'AND USERID = ''' LV_USERID '''' INTO LV_SQL_STR.
        ENDIF.
      ENDIF.

    ELSE.
      LV_SQL_STR = IV_FILTER_STRING.
    ENDIF.

    SELECT *
      FROM YBC_SWS_REQJSON
      INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
      WHERE (LV_SQL_STR).
    IF SY-SUBRC <> 0.
      RETURN.

    ELSE.

      "top 和 skip实现
      DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

      LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
      LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
      IF LV_SKIP IS NOT INITIAL OR
        LV_TOP IS NOT INITIAL.

        DO LV_SKIP TIMES.
          DELETE ET_ENTITYSET INDEX 1.
        ENDDO.

        LOOP AT ET_ENTITYSET INTO DATA(LS_ENTITYSET).
          IF SY-TABIX > LV_TOP.
            DELETE ET_ENTITYSET.
          ENDIF.

        ENDLOOP.
      ENDIF.
    ENDIF.

    IF IT_ORDER[] IS NOT INITIAL.
      DATA:
        LT_SORT TYPE ABAP_SORTORDER_TAB,
        LS_SORT TYPE ABAP_SORTORDER.

      LOOP AT IT_ORDER INTO DATA(LS_ORDER).
        CLEAR LS_SORT.
        LS_SORT-NAME = LS_ORDER-PROPERTY.
        IF LS_ORDER-ORDER = 'desc'.
          LS_SORT-DESCENDING = 'X'.
        ENDIF.
        APPEND LS_SORT TO LT_SORT.
      ENDLOOP.
      SORT ET_ENTITYSET BY (LT_SORT).
    ENDIF.
  ENDMETHOD.


  METHOD REQUESTSET_GET_ENTITY.
    DATA:
      LV_REQUESTID TYPE YBC_SWS_REQUEST-REQUESTID,
      LS_KEY_TAB   TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR.

    DATA:
      LS_REQUEST_DB TYPE YBC_SWS_REQUEST,
      LS_MESSAGE    TYPE SCX_T100KEY.

   "Fiori 不会调用
    CLEAR LS_KEY_TAB.
    READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'Requestid'.
    LV_REQUESTID = LS_KEY_TAB-VALUE.

    SELECT SINGLE *
      FROM YBC_SWS_REQUEST
      INTO LS_REQUEST_DB
      WHERE REQUESTID = LV_REQUESTID.
    IF SY-SUBRC <> 0.
      RETURN.
    ELSE.
      MOVE-CORRESPONDING LS_REQUEST_DB TO ER_ENTITY.
      ER_ENTITY-CDATETIME = LS_REQUEST_DB-CDATE && LS_REQUEST_DB-CTIME.

      SELECT SINGLE
        FLG_UPLOAD
        INTO ER_ENTITY-FLAG_UPLOAD
        FROM YBC_SWS_APP_CNFG
       WHERE APPID = LS_REQUEST_DB-APPID.
    ENDIF.
  ENDMETHOD.


  METHOD REQUESTSET_GET_ENTITYSET.
    TYPES:
      BEGIN OF LY_YBC_SWS_USER,
        USERID TYPE YBC_SWS_USERID, "User ID
        NAME1  TYPE YBC_SWS_NAME1, "Chinese Name
      END OF LY_YBC_SWS_USER,

      BEGIN OF LY_YBC_SWS_APPROVER,
        REQUESTID  TYPE YBC_SWS_REQUESTID, "Request ID
        APPROVERID TYPE YBC_SWS_USERID, "User ID
        APPLEVEL   TYPE YBC_SWS_APPLEVEL, "Approval level
        VERSION    TYPE VERSION, "Object version
        ACTION     TYPE YBC_SWS_ACTION, "Action
        RDATE      TYPE YBC_SWS_RDATE, "Received Date
        RTIME      TYPE YBC_SWS_RTIME, "Received Time
        ADATE      TYPE YBC_SWS_ADATE, "Approval date
        ATIME      TYPE YBC_SWS_ATIME, "Approval Time
      END OF LY_YBC_SWS_APPROVER.

    DATA:
      LV_TOP  TYPE I,
      LV_SKIP TYPE I.

    DATA:

      LS_YBC_SWS_USER_TMP     TYPE LY_YBC_SWS_USER,
      LT_YBC_SWS_USER_TMP     TYPE TABLE OF LY_YBC_SWS_USER,
      LS_YBC_SWS_USER         TYPE LY_YBC_SWS_USER,
      LT_YBC_SWS_USER         TYPE TABLE OF LY_YBC_SWS_USER,
      LV_TIMESTAMP            TYPE TIMESTAMP,
      LV_SQL_STR              TYPE STRING,
      LV_PROCESSED            TYPE YBC_SWS_APPROVER-PROCESSED,
      LV_INDEX                TYPE NUM2,
      LV_LANGUAGE             TYPE CHAR10,
      LV_FIELD                TYPE STRING,
      LS_YBC_SWS_APPROVER     TYPE LY_YBC_SWS_APPROVER,
      LS_YBC_SWS_APPROVER_TMP TYPE LY_YBC_SWS_APPROVER,
      LT_YBC_SWS_APPROVER     TYPE TABLE OF LY_YBC_SWS_APPROVER,
      LT_YBC_SWS_APPROVER_TMP TYPE TABLE OF LY_YBC_SWS_APPROVER,
      LR_APPROVERID           TYPE /IWBEP/S_COD_SELECT_OPTION,
      LS_FILTER               TYPE /IWBEP/S_MGW_SELECT_OPTION,
      LS_FILTER1              TYPE /IWBEP/S_MGW_SELECT_OPTION,
      LT_RANGE01              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE02              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE03              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE04              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE05              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE06              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE07              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE08              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE09              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LT_RANGE10              TYPE /IWBEP/T_COD_SELECT_OPTIONS,
      LS_APPROVER             TYPE YBC_SWS_APPROVER,
      LT_APPROVER             TYPE STANDARD TABLE OF YBC_SWS_APPROVER,
      LV_USERID               TYPE YBC_SWS_REQUEST-USERID,
      LS_ENTITYSET            LIKE LINE OF ET_ENTITYSET,
      LS_REQUEST_DB           TYPE YBC_SWS_REQUEST,
      LT_REQUEST_DB           TYPE STANDARD TABLE OF YBC_SWS_REQUEST,
      LS_MESSAGE              TYPE SCX_T100KEY.

    FIELD-SYMBOLS <FS_FIELD> TYPE ANY TABLE.

    CLEAR LS_FILTER.
    READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
      WITH KEY PROPERTY = 'Approverid'.

    IF SY-SUBRC <> 0."不传账号则用SAP 登陆的用户ID作为审批人
      CLEAR LR_APPROVERID.
      LR_APPROVERID-SIGN = 'I'.
      LR_APPROVERID-OPTION = 'EQ'.
      SELECT SINGLE
        USERID
        INTO LR_APPROVERID-LOW
        FROM YBC_SWS_USER
       WHERE SAPID = SY-UNAME.

      IF SY-SUBRC <> 0.
*        LS_MESSAGE-MSGID = 'YBC_SWS'.
*        LS_MESSAGE-MSGNO = '014'.
*        LS_MESSAGE-ATTR1 = SY-UNAME.
*        RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
*          EXPORTING
*            TEXTID = LS_MESSAGE.
        RETURN.
      ENDIF.

      APPEND LR_APPROVERID TO LS_FILTER-SELECT_OPTIONS.
    ENDIF.

    "Outbox 查询标识
    CLEAR LS_FILTER1.
    READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER1
      WITH KEY PROPERTY = 'Status'.

    CLEAR LV_PROCESSED.
    LOOP AT LS_FILTER1-SELECT_OPTIONS TRANSPORTING NO FIELDS
      WHERE LOW = 'F'. "Finished
      LV_PROCESSED = 'X'. "查找处理过的单子
      EXIT.
    ENDLOOP.

    SELECT *
      INTO TABLE LT_APPROVER
      FROM YBC_SWS_APPROVER
     WHERE APPROVERID IN LS_FILTER-SELECT_OPTIONS
       AND PROCESSED = LV_PROCESSED
       AND ACTUALPROCESSED = LV_PROCESSED. "查outbox时实际处理者标识也要加上
    IF SY-SUBRC <> 0.
      RETURN.
    ENDIF.

    LV_INDEX = 0.
    LOOP AT IT_FILTER_SELECT_OPTIONS INTO LS_FILTER WHERE PROPERTY <> 'Approverid'
      AND PROPERTY <> 'Status' AND PROPERTY <> 'Message'.
      LV_INDEX = LV_INDEX + 1.
      LV_FIELD = 'LT_RANGE' && LV_INDEX.
      ASSIGN (LV_FIELD) TO <FS_FIELD>.
      <FS_FIELD> = LS_FILTER-SELECT_OPTIONS.

      IF LV_INDEX <= 1.
        CONCATENATE LS_FILTER-PROPERTY 'IN' LV_FIELD INTO
          LV_SQL_STR  SEPARATED BY SPACE.
      ELSE.
        CONCATENATE LV_SQL_STR 'AND' LS_FILTER-PROPERTY 'IN' LV_FIELD INTO
           LV_SQL_STR  SEPARATED BY SPACE.
      ENDIF.

      IF LV_INDEX >= 10.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF IT_KEY_TAB[] IS NOT INITIAL.
      READ TABLE IT_KEY_TAB INTO DATA(LS_KEY_TAB)
        WITH KEY NAME = 'Userid'.
      LV_USERID = LS_KEY_TAB-VALUE.
      CONDENSE LV_USERID.
      IF LV_USERID IS NOT INITIAL.
        IF LV_SQL_STR IS INITIAL.
          CONCATENATE 'USERID = ''' LV_USERID '''' INTO LV_SQL_STR.
        ELSE.
          CONCATENATE LV_SQL_STR 'AND USERID = ''' LV_USERID '''' INTO LV_SQL_STR.
        ENDIF.
      ENDIF.
    ENDIF.

*    IF LT_APPROVER IS NOT INITIAL.
*      SELECT *
*        FROM YBC_SWS_REQUEST
*        INTO TABLE LT_REQUEST_DB
*        FOR ALL ENTRIES IN LT_APPROVER
*        WHERE REQUESTID = LT_APPROVER-REQUESTID
*          "AND MOD = 'NEW'
*          AND (LV_SQL_STR).
*    ELSE.
*      SELECT *
*        FROM YBC_SWS_REQUEST
*        INTO TABLE LT_REQUEST_DB
*       WHERE MOD = 'NEW'
*         AND (LV_SQL_STR).
*    ENDIF.
    IF LV_PROCESSED IS INITIAL. "Inbox
      SELECT *
        FROM YBC_SWS_REQUEST
        INTO TABLE LT_REQUEST_DB
         FOR ALL ENTRIES IN LT_APPROVER
       WHERE REQUESTID = LT_APPROVER-REQUESTID
         AND STATUS IN ('0', '1')
         AND (LV_SQL_STR).
    ELSE. "Outbox
      SELECT *
        FROM YBC_SWS_REQUEST
        INTO TABLE LT_REQUEST_DB
         FOR ALL ENTRIES IN LT_APPROVER
       WHERE REQUESTID = LT_APPROVER-REQUESTID
         AND (LV_SQL_STR).
    ENDIF.
    IF SY-SUBRC <> 0.
      RETURN.
    ELSE.

      "非outbox情况下，取应用配置相关信息,
      IF LV_PROCESSED IS INITIAL.
        SELECT
          APPID,
          FLG_UPLOAD
          INTO TABLE @DATA(LT_APP_CNFG)
          FROM YBC_SWS_APP_CNFG
          FOR ALL ENTRIES IN @LT_REQUEST_DB
         WHERE APPID = @LT_REQUEST_DB-APPID.

        SORT LT_APP_CNFG BY APPID.
      ENDIF.

      "多语言
      CLEAR LS_FILTER.
      READ TABLE IT_FILTER_SELECT_OPTIONS INTO LS_FILTER
        WITH KEY PROPERTY = 'Message'.
      LOOP AT LS_FILTER-SELECT_OPTIONS INTO DATA(LS_LANGUAGE).
        LV_LANGUAGE = LS_LANGUAGE-LOW.
        EXIT.
      ENDLOOP.
      IF LV_LANGUAGE IS INITIAL.
        LV_LANGUAGE = 'zh'. "默认中文
      ENDIF.
      TRANSLATE LV_LANGUAGE TO LOWER CASE.

      LOOP AT LT_REQUEST_DB INTO LS_REQUEST_DB.
        CLEAR LS_ENTITYSET.
        IF LV_LANGUAGE CS 'zh'.
          LS_REQUEST_DB-SUBJECT3 = LS_REQUEST_DB-SUBJECT1.
          LS_REQUEST_DB-CATEGORY3 = LS_REQUEST_DB-CATEGORY1.
          LS_REQUEST_DB-SUBCATEGORY3 = LS_REQUEST_DB-SUBCATEGORY1.
        ELSEIF LV_LANGUAGE CS 'en'.
          LS_REQUEST_DB-SUBJECT3 = LS_REQUEST_DB-SUBJECT2.
          LS_REQUEST_DB-CATEGORY3 = LS_REQUEST_DB-CATEGORY2.
          LS_REQUEST_DB-SUBCATEGORY3 = LS_REQUEST_DB-SUBCATEGORY2.
        ENDIF.
        MOVE-CORRESPONDING LS_REQUEST_DB TO LS_ENTITYSET.
        LS_ENTITYSET-CDATETIME = LS_REQUEST_DB-CDATE && LS_REQUEST_DB-CTIME.

        READ TABLE LT_APPROVER INTO LS_APPROVER WITH KEY REQUESTID = LS_REQUEST_DB-REQUESTID.
        IF SY-SUBRC = 0.
          LS_ENTITYSET-APPROVERID = LS_APPROVER-APPROVERID.
          LS_ENTITYSET-APPLEVEL = LS_APPROVER-APPLEVEL.
          LS_ENTITYSET-APPLEVEL_DESC1 = LS_APPROVER-APPLEVEL_DESC1.
          LS_ENTITYSET-APPLEVEL_DESC2 = LS_APPROVER-APPLEVEL_DESC2.
          LS_ENTITYSET-APPLEVEL_DESC3 = LS_APPROVER-APPLEVEL_DESC3.
          LS_ENTITYSET-LASTPROCDT = LS_APPROVER-ADATE && LS_APPROVER-ATIME.
        ENDIF.

        "能否上传附件标识
        IF LV_PROCESSED IS INITIAL.
          READ TABLE LT_APP_CNFG INTO DATA(LS_APP_CNFG)
            WITH KEY APPID = LS_REQUEST_DB-APPID BINARY SEARCH.
          IF SY-SUBRC = 0.
            LS_ENTITYSET-FLAG_UPLOAD = LS_APP_CNFG-FLG_UPLOAD.
          ENDIF.
        ENDIF.

        CLEAR LS_YBC_SWS_APPROVER_TMP.
        LS_YBC_SWS_APPROVER_TMP-REQUESTID = LS_ENTITYSET-REQUESTID.
        COLLECT LS_YBC_SWS_APPROVER_TMP INTO LT_YBC_SWS_APPROVER_TMP.

        CLEAR LS_YBC_SWS_USER_TMP.
         LS_YBC_SWS_USER_TMP-USERID =  LS_ENTITYSET-USERID.
        COLLECT LS_YBC_SWS_USER_TMP INTO LT_YBC_SWS_USER_TMP.
        APPEND LS_ENTITYSET TO ET_ENTITYSET.
      ENDLOOP.

      IF LT_YBC_SWS_APPROVER_TMP[] IS NOT INITIAL.
        SELECT
          REQUESTID "Request ID
          APPROVERID "User ID
          APPLEVEL "Approval level
          VERSION "Object version
          ACTION "Action
          RDATE "Received Date
          RTIME "Received Time
          ADATE "Approval date
          ATIME "Approval Time
          INTO TABLE LT_YBC_SWS_APPROVER
          FROM YBC_SWS_APPROVER FOR ALL ENTRIES IN LT_YBC_SWS_APPROVER_TMP
          WHERE REQUESTID = LT_YBC_SWS_APPROVER_TMP-REQUESTID
            AND ACTUALPROCESSED = 'X'.
        SORT LT_YBC_SWS_APPROVER BY REQUESTID ADATE DESCENDING  ATIME DESCENDING.


      ENDIF.

      IF LT_YBC_SWS_USER_TMP[] IS NOT INITIAL.
        SELECT
          USERID "User ID
          NAME1 "Chinese Name
          INTO TABLE LT_YBC_SWS_USER
          FROM YBC_SWS_USER FOR ALL ENTRIES IN LT_YBC_SWS_USER_TMP
          WHERE USERID = LT_YBC_SWS_USER_TMP-USERID.
        SORT LT_YBC_SWS_USER BY USERID.
      ENDIF.

      LOOP AT ET_ENTITYSET INTO LS_ENTITYSET.
        READ TABLE LT_YBC_SWS_APPROVER INTO LS_YBC_SWS_APPROVER
          WITH KEY  REQUESTID = LS_ENTITYSET-REQUESTID
          BINARY SEARCH.
        IF SY-SUBRC = 0.
*          CLEAR LV_TIMESTAMP.
*          CONVERT DATE LS_YBC_SWS_APPROVER-ADATE TIME LS_YBC_SWS_APPROVER-ATIME
*            INTO TIME STAMP LV_TIMESTAMP  TIME ZONE SY-ZONLO.
*           LS_ENTITYSET-LASTPROCDT = LV_TIMESTAMP.
          CONCATENATE LS_YBC_SWS_APPROVER-ADATE LS_YBC_SWS_APPROVER-ATIME
            INTO LS_ENTITYSET-LASTPROCDT.

        ELSE.
          LS_ENTITYSET-LASTPROCDT = LS_ENTITYSET-CDATETIME.
        ENDIF.

        READ TABLE LT_YBC_SWS_USER INTO LS_YBC_SWS_USER
          WITH KEY USERID = LS_ENTITYSET-USERID
          BINARY SEARCH.
        IF SY-SUBRC = 0.
          LS_ENTITYSET-SUBMITER = LS_YBC_SWS_USER-NAME1.
        ENDIF.
        MODIFY ET_ENTITYSET FROM LS_ENTITYSET.
      ENDLOOP.

      SORT ET_ENTITYSET BY LASTPROCDT DESCENDING.
      "top 和 skip实现
      DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

      LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
      LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
      IF LV_SKIP IS NOT INITIAL OR
        LV_TOP IS NOT INITIAL.

        DO LV_SKIP TIMES.
          DELETE ET_ENTITYSET INDEX 1.
        ENDDO.

        LOOP AT ET_ENTITYSET INTO LS_ENTITYSET.
          IF SY-TABIX > LV_TOP.
            DELETE ET_ENTITYSET.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDIF.

    IF IT_ORDER[] IS NOT INITIAL.
      DATA:
        LT_SORT TYPE ABAP_SORTORDER_TAB,
        LS_SORT TYPE ABAP_SORTORDER.

      LOOP AT IT_ORDER INTO DATA(LS_ORDER).
        CLEAR LS_SORT.
        LS_SORT-NAME = LS_ORDER-PROPERTY.
        IF LS_ORDER-ORDER = 'desc'.
          LS_SORT-DESCENDING = 'X'.
        ENDIF.
        APPEND LS_SORT TO LT_SORT.
      ENDLOOP.
      SORT ET_ENTITYSET BY (LT_SORT).
    ENDIF.
  ENDMETHOD.


  METHOD USERSET_GET_ENTITY.
    DATA:
      LV_OK       TYPE C,
      LV_USERID   TYPE YBC_SWS_USER-USERID,
      LV_PASSWORD TYPE TEXT100,
      LS_KEY_TAB  TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR,
      LS_MESSAGE  TYPE SCX_T100KEY.

    CLEAR LS_KEY_TAB.
    READ TABLE IT_KEY_TAB INTO LS_KEY_TAB WITH KEY NAME = 'Userid'.
    LV_USERID = LS_KEY_TAB-VALUE.
    CONDENSE LV_USERID.
    TRANSLATE LV_USERID TO UPPER CASE.

    IF LV_USERID IS INITIAL.
      RETURN.
    ENDIF.

    IF LV_USERID = '###DEFAULTSAPUSER###'.
      LV_USERID = SY-UNAME.
    ENDIF.

    "按SAP账号找
    SELECT SINGLE *
      FROM YBC_SWS_USER
      INTO CORRESPONDING FIELDS OF ER_ENTITY
      WHERE SAPID = LV_USERID.
    IF SY-SUBRC = 0.
      LV_OK = 'X'.
    ENDIF.

    "按外部账号找
    IF LV_OK IS INITIAL.
      SELECT SINGLE *
        FROM YBC_SWS_USER
        INTO CORRESPONDING FIELDS OF ER_ENTITY
        WHERE EXTUSID = LV_USERID.
      IF SY-SUBRC = 0.
        LV_OK = 'X'.
      ENDIF.
    ENDIF.

*    "按Email找
*    IF LV_OK IS INITIAL.
*      SELECT SINGLE *
*        FROM YBC_SWS_USER
*        INTO CORRESPONDING FIELDS OF ER_ENTITY
*        WHERE EMAIL = LV_USERID.
*      IF SY-SUBRC = 0.
*        LV_OK = 'X'.
*      ENDIF.
*    ENDIF.
*
*    "按Tel找
*    IF LV_OK IS INITIAL.
*      SELECT SINGLE *
*        FROM YBC_SWS_USER
*        INTO CORRESPONDING FIELDS OF ER_ENTITY
*        WHERE TEL = LV_USERID.
*      IF SY-SUBRC = 0.
*        LV_OK = 'X'.
*      ENDIF.
*    ENDIF.
*
*    "按WECHAT找
*    IF LV_OK IS INITIAL.
*      SELECT SINGLE *
*        FROM YBC_SWS_USER
*        INTO CORRESPONDING FIELDS OF ER_ENTITY
*        WHERE WECHAT = LV_USERID.
*      IF SY-SUBRC = 0.
*        LV_OK = 'X'.
*      ENDIF.
*    ENDIF.

    "按USERID找
    IF LV_OK IS INITIAL.
      SELECT SINGLE *
        FROM YBC_SWS_USER
        INTO CORRESPONDING FIELDS OF ER_ENTITY
        WHERE USERID = LV_USERID.
      IF SY-SUBRC = 0.
        LV_OK = 'X'.
      ENDIF.
    ENDIF.

    IF ER_ENTITY-USERID IS NOT INITIAL.
      TYPES:
        BEGIN OF TY_SUBCATEGORIES,
          KEY          TYPE STRING,
          SUBCATEGORY1 TYPE YBC_SWS_REQUEST-SUBCATEGORY1,
          SUBCATEGORY2 TYPE YBC_SWS_REQUEST-SUBCATEGORY2,
          SUBCATEGORY3 TYPE YBC_SWS_REQUEST-SUBCATEGORY3,
        END OF TY_SUBCATEGORIES.

      DATA:
        LS_SUBCAT TYPE TY_SUBCATEGORIES,
        LT_SUBCAT TYPE STANDARD TABLE OF TY_SUBCATEGORIES.

      SELECT
        SUBCATEGORY1
        SUBCATEGORY2
        SUBCATEGORY3
        INTO CORRESPONDING FIELDS OF TABLE LT_SUBCAT
        FROM YBC_SWS_REQUEST
        JOIN YBC_SWS_APPROVER
          ON YBC_SWS_REQUEST~REQUESTID = YBC_SWS_APPROVER~REQUESTID
       WHERE YBC_SWS_APPROVER~APPROVERID = ER_ENTITY-USERID
         AND YBC_SWS_REQUEST~MOD = 'NEW'.

      SORT LT_SUBCAT BY SUBCATEGORY1 SUBCATEGORY2 SUBCATEGORY3.
      DELETE ADJACENT DUPLICATES FROM LT_SUBCAT.

      DELETE LT_SUBCAT WHERE SUBCATEGORY1 IS INITIAL AND SUBCATEGORY2 IS INITIAL AND SUBCATEGORY3 IS INITIAL.
      LOOP AT LT_SUBCAT INTO LS_SUBCAT.
        LS_SUBCAT-KEY = 'SUBCATKEY' && SY-TABIX.
        MODIFY LT_SUBCAT FROM LS_SUBCAT.
      ENDLOOP.

      "SwiftSAP Host
      SELECT SINGLE
        VALUE
        INTO ER_ENTITY-SWIFTSAPHOST
        FROM YBC_SWS_CONTR
       WHERE PARAM IN ('SWIFTSAPHOST', 'SWIFTSAP_HOST')
         AND ACTIVE = 'X'.

      CONDENSE ER_ENTITY-SWIFTSAPHOST.

      ER_ENTITY-SUBCATEGORIES = /UI2/CL_JSON=>SERIALIZE( DATA = LT_SUBCAT ).
    ENDIF.

  ENDMETHOD.


  METHOD USERSET_GET_ENTITYSET.
    DATA:
      LV_TOP     TYPE I,
      LV_SKIP    TYPE I,
      LS_MESSAGE TYPE SCX_T100KEY.

    "Fiori 不会调用

    SELECT *
      FROM YBC_SWS_USER
      INTO CORRESPONDING FIELDS OF TABLE ET_ENTITYSET
      WHERE (IV_FILTER_STRING).
    IF SY-SUBRC <> 0.
      RETURN.
    ELSE.

      "top 和 skip实现
      DESCRIBE TABLE ET_ENTITYSET LINES ES_RESPONSE_CONTEXT-COUNT.

      LV_TOP = IO_TECH_REQUEST_CONTEXT->GET_TOP( ).
      LV_SKIP = IO_TECH_REQUEST_CONTEXT->GET_SKIP( ).
      IF LV_SKIP IS NOT INITIAL OR
        LV_TOP IS NOT INITIAL.

        DO LV_SKIP TIMES.
          DELETE ET_ENTITYSET INDEX 1.
        ENDDO.

        LOOP AT ET_ENTITYSET INTO DATA(LS_ENTITYSET).
          IF SY-TABIX > LV_TOP.
            DELETE ET_ENTITYSET.
          ENDIF.

        ENDLOOP.
      ENDIF.
    ENDIF.

    IF IT_ORDER[] IS NOT INITIAL.
      DATA:
        LT_SORT TYPE ABAP_SORTORDER_TAB,
        LS_SORT TYPE ABAP_SORTORDER.

      LOOP AT IT_ORDER INTO DATA(LS_ORDER).
        CLEAR LS_SORT.
        LS_SORT-NAME = LS_ORDER-PROPERTY.
        IF LS_ORDER-ORDER = 'desc'.
          LS_SORT-DESCENDING = 'X'.
        ENDIF.
        APPEND LS_SORT TO LT_SORT.
      ENDLOOP.
      SORT ET_ENTITYSET BY (LT_SORT).
    ENDIF.
  ENDMETHOD.
ENDCLASS.
